/**
 * Permiso.java
 */

 /**
 *  AdSec: Administrador de Secundarias
 *  Copyright (C) 2009 Daniela Ramírez Chaves (dannyrch@gmail.com)
 *  Copyright (C) 2009 Leonel Salazar Valverde (leo87sv@gmail.com)
 *
 *  This file is part of AdSec.
 *  AdSec is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  AdSec is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with AdSec.  If not, see <http://www.gnu.org/licenses/>.
 */

package adsec.entidades;

/**
 *
 * @author konata
 */
public class Permiso {

    private boolean insertar;
    private boolean modificar;
    private boolean eliminar;
    private boolean consultar;

    private final char HABILITADO = '1';
    private final char DESHABILITADO = '0';

    public Permiso(){
        this.insertar = false;
        this.modificar = false;
        this.eliminar = false;
        this.consultar = false;
    }//fin de constructor

    public Permiso(String permisos){
        char caracter = permisos.charAt(0);
        this.insertar = caracter == HABILITADO;
        caracter = permisos.charAt(1);
        this.modificar = caracter == HABILITADO;
        caracter = permisos.charAt(2);
        this.eliminar = caracter == HABILITADO;
        caracter = permisos.charAt(3);
        this.consultar = caracter == HABILITADO;
    }//fin de constructor

    public Permiso( boolean insertar, boolean modificar, boolean eliminar, boolean consultar){
        this.insertar = insertar;
        this.modificar = modificar;
        this.eliminar = eliminar;
        this.consultar = consultar;
    }//fin de constructor

    public void setPermisos(boolean insertar, boolean modificar, boolean eliminar, boolean consultar){
        this.insertar = insertar;
        this.modificar = modificar;
        this.eliminar = eliminar;
        this.consultar = consultar;
    }//fin de setPermisos

    @Override
    public String toString(){
        StringBuffer permisos = new StringBuffer();
        if(this.insertar){
            permisos.append(HABILITADO);
        }else{
            permisos.append(DESHABILITADO);
        }

        if(this.modificar){
            permisos.append(HABILITADO);
        }else{
            permisos.append(DESHABILITADO);
        }

        if(this.eliminar){
            permisos.append(HABILITADO);
        }else{
            permisos.append(DESHABILITADO);
        }

        if(this.consultar){
            permisos.append(HABILITADO);
        }else{
            permisos.append(DESHABILITADO);
        }

        return permisos.toString();
    }//fin de toString

    /**
     * @return the insertar
     */
    public boolean isInsertar() {
        return insertar;
    }

    /**
     * @param insertar the insertar to set
     */
    public void setInsertar(boolean insertar) {
        this.insertar = insertar;
    }

    /**
     * @return the modificar
     */
    public boolean isModificar() {
        return modificar;
    }

    /**
     * @param modificar the modificar to set
     */
    public void setModificar(boolean modificar) {
        this.modificar = modificar;
    }

    /**
     * @return the eliminar
     */
    public boolean isEliminar() {
        return eliminar;
    }

    /**
     * @param eliminar the eliminar to set
     */
    public void setEliminar(boolean eliminar) {
        this.eliminar = eliminar;
    }

    /**
     * @return the consultar
     */
    public boolean isConsultar() {
        return consultar;
    }

    /**
     * @param consultar the consultar to set
     */
    public void setConsultar(boolean consultar) {
        this.consultar = consultar;
    }


}
